# 升级时的备份镜像 registry.erda.cloud/erda/terminus-maven:3-jdk-8-alpine-back
# registry.erda.cloud/erda/terminus-maven:3-jdk-8-alpine
FROM alpine:3.12

# set repository
# https://pkgs.alpinelinux.org/packages?name=openjdk8-jre-lib&branch=edge
RUN echo "http://mirrors.aliyun.com/alpine/v3.12/main/" > /etc/apk/repositories && echo "http://mirrors.aliyun.com/alpine/v3.12/community/" >> /etc/apk/repositories

# adjust timezone
RUN apk add --no-cache tzdata && \
  cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
  echo "Asia/Shanghai" > /etc/timezone && \
  date && \
  apk del tzdata

# add other pkgs
RUN apk add --no-cache bash python2 python3 curl

# add openjdk8
ENV JAVA_VERSION 8u275
ENV JAVA_ALPINE_VERSION 8.275.01-r0
RUN apk upgrade --no-cache && apk add --no-cache openjdk8

# add maven, ref: https://github.com/carlossg/docker-maven/blob/master/openjdk-8/Dockerfile
ARG MAVEN_VERSION=3.6.3
ARG USER_HOME_DIR="/root"
ARG SHA=c35a1803a6e70a126e80b2b3ae33eed961f83ed74d18fcd16909b2d44d7dada3203f1ffe726c17ef8dcca2dcaa9fca676987befeadc9b9f759967a8cb77181c0
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries

RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
  && curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
  && echo "${SHA}  /tmp/apache-maven.tar.gz" | sha512sum -c - \
  && tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
  && rm -f /tmp/apache-maven.tar.gz \
  && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn

ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"

COPY mvn-entrypoint.sh /usr/local/bin/mvn-entrypoint.sh
COPY settings-docker.xml /usr/share/maven/ref/

RUN /usr/local/bin/mvn-entrypoint.sh
